package day07_Array;
//StringBuilder和String的相互转换
//1.StringBuilder转为String
//	public String toString()

//2.String转为StringBuilder
//	public StringBuilder(String str)
public class Demo04_StringTOStringBulid {
    public static void main(String[] args) {
        String str="123456";
        String newStr="";
        //直接反转String  把反转的结果重新复制给newstr
        for (int i = str.length()-1; i >=0 ; i--) {
            //System.out.print(str.charAt(i));//654321
            newStr+=str.charAt(i);
        }
        System.out.println(newStr);//654321

        StringBuilder sb=new StringBuilder("123456");
        sb.reverse();//反转
        System.out.println(sb);//654321

        String s1="abcdefg";
        StringBuilder sb1 = new StringBuilder(s1);
        sb1.reverse();//反转
        System.out.println(sb1);//gfedcba
        //StringBuilder转为String
        String s2 = sb1.toString();
        System.out.println(s2);//gfedcba

    }
}
